import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:message_tools/components/appbar_plugins.dart';
import 'package:message_tools/components/index.dart';
import 'package:message_tools/store/index.dart';
import 'package:message_tools/store/view_model/index.dart';

const buttonHeight = 50.0;
const rightButtonHeight = 40.0;

/// ListView 默认的实例,无状态
class SendResultListPage extends StatefulWidget {
  String title = "";

  SendResultListPage(this.title);

  @override
  _SendResultListPageState createState() => _SendResultListPageState();
}

class _SendResultListPageState extends State<SendResultListPage> {
  @override
  void initState() {
    super.initState();
  }

  Widget build(BuildContext context) {
    //var store = Store.value<SmsSendRecordModel>(context);
    //store.loadNotSendSms(0, 10000);

    return Scaffold(
      appBar: AppBarPlugin.Create(widget.title, centerTitle: true,
          leading: Builder(builder: (BuildContext c) {
        return IconButton(
            icon: const Icon(Icons.arrow_back),
            onPressed: () {
              Navigator.pop(context);
            });
      })),
      body: Theme.of(context).platform == TargetPlatform.iOS
          ? CupertinoScrollbar(
              child: _createListView(),
            )
          : Scrollbar(
              child: _createListView(),
            ),
      resizeToAvoidBottomPadding: false,
    );
  }

  _createListView() {
    return Store.connect<SmsSendRecordModel>(
        builder: (context, snapshot, child) {
      return _buildListViewItem(snapshot.list);
    });
  }

  Widget _buildListViewItem(List list) {
    return ListView.builder(
        padding: new EdgeInsets.all(5),
        scrollDirection: Axis.vertical,
        itemCount: list.length, // item 的个数
        itemExtent: 50.0,
        itemBuilder: (BuildContext context, int index) {
          var item = list[index];
          return Container(
              margin: const EdgeInsets.all(5),
              padding: const EdgeInsets.all(10),
              decoration: new BoxDecoration(
                //背景
                color: Colors.white,
                //设置四周边框
                border: createBorder(color: Colors.grey[300]),
              ),
              child: Text("第${item.nindex}行: ${item.phoneNum}"));
        });
  }
}
